package cn.thornbird.orgsync.vo.request;

import cn.thornbird.orgsync.constraints.FieldsValueMatch;
import cn.thornbird.orgsync.vo.record.SimpleUserRecord;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
@FieldsValueMatch(first = "newPassword", second = "confirmPassword", message = "新密码与确认密码不一致")
public class ChangePasswordRequest {

    @NotBlank(message = "旧密码不能为空")
    private String oldPassword;

    @NotBlank(message = "新密码不能为空")
    @Size(min = 6, max = 16, message = "密码长度为6-16位")
    @Pattern(regexp = SimpleUserRecord.PASSWORD_REG_EXP, message = "密码必须包含数字，且必须包含字母或其它字符（!@_#$%^&*()-+=,.?）")
    private String newPassword;

    @NotBlank(message = "确认密码不能为空")
    private String confirmPassword;

    @NotNull(message = "有效期不能为空")
    @Valid
    private PeriodOfValidity periodOfValidity;


    @Data
    public static class PeriodOfValidity {

        @NotNull(message = "有效期-月不能为空")
        private Integer months;

        @NotNull(message = "有效期-从不过期不能为空")
        private Boolean neverExpire;

    }
}
